﻿using System.Collections.Generic;
using System.Web.Mvc;
using Business;
using Dto;

namespace YaoYunDong.Controllers
{
    public class PersonalController : Controller
    {
        private readonly UserBusiness userBusiness = new UserBusiness();
        private readonly MovingBusiness movingBusiness = new MovingBusiness();

        public ActionResult Index(int id, int? currentPageNo)
        {
            UsersDto mySelf = null;
            if (Session["User"] != null)
            {
                mySelf = Session["User"] as UsersDto;
            }

            var userDto = userBusiness.GetUsersById(id);
            ViewData["MySelf"] = mySelf;
            ViewData["MyWishCount"] = userBusiness.GetMyWishCount(userDto.UserId);
            ViewData["FollowMeCount"] = userBusiness.GetFollowMeCount(userDto.UserId);
            ViewData["JoinGroupCount"] = userBusiness.GetJoinGroupCount(userDto.UserId);
            int totalCount;
            var dtos = movingBusiness.GetUserMovings(currentPageNo ?? 1, 20, id, out totalCount);
            var pageDto = new PagingDto(totalCount, currentPageNo ?? 1, 20, dtos ?? new List<UserMovingDto>());
            ViewData["Pages"] = pageDto;
            return View(userDto);
        }
    }
}
